package com.zhiyou.servlrt.log;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhiyou.service.LogService;
import com.zhiyou.serviceImpl.LogServiceImpl;

/**
 * Servlet implementation class LogAddServlet
 */
@WebServlet("/LogAddServlet")
public class LogAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LogAddServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		LogService ls = new LogServiceImpl();
		String name = request.getParameter("lo_name");
		String card = request.getParameter("lo_id_card");
		String phone = request.getParameter("lo_phone");
		String sex = request.getParameter("lo_sex");
		String post = request.getParameter("lo_post");
		double sal = Double.parseDouble(request.getParameter("lo_sal"));
		String place = request.getParameter("lo_native_place"); 
		Object obj[] = {name,card,phone,sex,post,sal,place};
		boolean flag = ls.add(obj);
		if(flag){
			request.setAttribute("msg", "创建成功");
			request.getRequestDispatcher("/LogShowServlet?1=1").forward(request, response);
		}else{
			request.setAttribute("msg", "创建失败");
			request.getRequestDispatcher("view/logistics/add.jsp").forward(request, response);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
